namespace Warehouse

open System.Windows.Data
open FSharp.Windows
open Warehouse.Controls

type ClientDetailsEvents = 
    | Save of (unit -> unit)
    | SameAsBilling 

type ClientDetailsView() as this = 
    inherit View<ClientDetailsEvents, ClientDetailsModel, ClientDetailsWindow>()
    
    let billToZipCode = this.Control.BillToZipCode
    let shipToZipCode = this.Control.ShipToZipCode

    do
       billToZipCode.EnsurePositiveInt()
       billToZipCode.MaxLength <- 5
       this.Control.BillToState.MaxLength <- 2
       shipToZipCode.EnsurePositiveInt()
       shipToZipCode.MaxLength <- 5
       this.Control.ShipToState.MaxLength <- 2

    override this.EventStreams = 
        [
            this.Control.Save, Save this.OK
            this.Control.SameAsBilling, SameAsBilling
        ] 
        |> List.ofButtonClicks


    override this.SetBindings model =
        Binding.FromExpression
            <@
                this.Control.CompanyName.Text <- model.CompanyName

                this.Control.BillToAddress.Text <- model.BillToAddress
                this.Control.BillToCity.Text <- model.BillToCity
                this.Control.BillToState.Text <- model.BillToState
                billToZipCode.Text <- model.BillToZipCode

                this.Control.ShipToAddress.Text <- model.ShipToAddress
                this.Control.ShipToCity.Text <- model.ShipToCity
                this.Control.ShipToState.Text <- model.ShipToState
                shipToZipCode.Text <- model.ShipToZipCode

                this.Control.EMail.Text <- model.EMail
                this.Control.Attn.Text <- model.Attn
                this.Control.Phone.Text <- model.Phone
            @>